package com.ruantu.clothing.service.impl;

import com.ruantu.clothing.dao.ChuKuDao;
import com.ruantu.clothing.dao.UserDao;
import com.ruantu.clothing.entity.User;
import com.ruantu.clothing.entity.print.PrintChuKuDan;
import com.ruantu.clothing.entity.print.PrintColor;
import com.ruantu.clothing.entity.print.PrintProduction;
import com.ruantu.clothing.service.PrintDanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/7/25 0025.
 */
@Service
@Transactional
public class PrintDanServiceImpl implements PrintDanService {
    @Autowired
    private ChuKuDao ckDao;

    @Autowired
    private UserDao userDao;
    /***
     * 打印单
     * @param chukuId
     * @return
     */
    @Override
    public Map<String, Object> printChuKuDan(String chukuId,String jgId) {
        Map<String, Object> mapCan = new HashMap<>();
        Map<String, Object> map = new HashMap<>();
        mapCan.put("chukuId", chukuId);
        mapCan.put("jgId",jgId);
        System.out.println("JFGIF:"+jgId);
        List<User> userList = userDao.selectAllUser();
        List<PrintChuKuDan> danList = ckDao.selectPrintChuKuDan(mapCan);
        List<PrintProduction> proList = ckDao.selectPrintChuKuDanProduction(mapCan);
        List<PrintColor> colorList = ckDao.selectPrintChuKuDanColor(mapCan);
        List<String> colorLista=new ArrayList<>();
        if (proList != null && proList.size() != 0) {
            for (int i = 0; i < proList.size(); i++) {
                if (colorList != null && colorList.size() != 0) {
                    for (int j = 0; j < colorList.size(); j++) {
                        if (colorList.get(j).getProductId().equals(proList.get(i).getProductId())) {
                            colorLista.add(colorList.get(j).getColor() + ":" + colorList.get(j).getColshuliang());
                        }
                    }
                }
                      proList.get(i).setColorArrayString(colorLista.toString());
                      colorLista.clear();
            }
        }

        if (danList != null && userList != null) {
            for (int i = 0; i < userList.size(); i++) {
                for (int j = 0; j < danList.size(); j++) {
                    if (danList.get(j).getZhidanren() != null && danList.get(j).getZhidanren() == userList.get(i).getId()) {
                        danList.get(j).setZhidanrenName(userList.get(i).getNikeName());
                    }

                    if (danList.get(j).getChukuren() != null && danList.get(j).getChukuren() == userList.get(i).getId()) {
                        danList.get(j).setChukurenName(userList.get(i).getNikeName());
                    }
                    if (danList.get(j).getShenheren() != null && danList.get(j).getShenheren() == userList.get(i).getId()) {

                        danList.get(j).setShenherenName(userList.get(i).getNikeName());

                    }


                }

            }

        }


        map.put("danList", danList);
        map.put("proList", proList);
        return map;
    }
}
